/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.statemachine.figure;

import java.util.Iterator;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.FigureListener;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.RoundedRectangle;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PrecisionRectangle;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.NamedElement;

import com.cea.papyrus.core.PapyrusPlugin;
import com.cea.papyrus.core.editpart.GraphNodeWithSemanticEditPart;
import com.cea.papyrus.core.figures.IAbstractElementFigure;
import com.cea.papyrus.core.helper.ModelerHelper;
import com.cea.papyrus.diagraminterchange2.di2.Diagram;
import com.cea.papyrus.diagraminterchange2.di2.GraphElement;
import com.cea.papyrus.diagraminterchange2.di2.Uml1SemanticModelBridge;

/**
 * This class is top graphNode figure.
 * It contains: 1 icone label + 1 stereotype label + 1 qualified nale label + 1 name label
 */
public class NodeFigure extends RoundedRectangle implements IAbstractElementFigure{

	/**
	 * The background color.
	 */
	protected Color backgroundColor = ColorConstants.lightBlue;
	
	/**
	 * The border color.
	 */
	protected Color borderColor     = ColorConstants.black;
	
	/**
	 * The fore ground color.
	 */
	protected Color foreGroundColor = ColorConstants.black;
	
	/**
	 * The font color.
	 */
	protected Color fontColor       = ColorConstants.black;

	/**
	 * The Line thickness.
	 */
	protected int LineThickness = 1;
	
	/**
	 * The font size.
	 */
	protected int fontSize      = 10;
	
	/**
	 * The line stle.
	 */
	protected String lineStle;
	
	/**
	 * The font string.
	 */
	protected String fontString = "Arial";
	
	/**
	 * The font.
	 */
	protected Font font = null;
	
	/**
	 * The img.
	 */
	protected Image img = null;

	/**
	 * The stereotypes label.
	 */
	protected Label stereotypesLabel;
	
	/**
	 * The icon label.
	 */
	protected Label iconLabel;	
	
	/**
	 * The name label.
	 */
	protected Label nameLabel;
	
	/**
	 * The qualified label.
	 */
	protected Label qualifiedLabel;


	/**
	 * Creat a basic figure.
	 */
	public NodeFigure() {
		super();
		FontData[] fontdata={new FontData(this.fontString, this.fontSize, SWT.NORMAL)};
		this.font = PapyrusPlugin.fontManager.get(fontdata);
		FontData[] fontdata2={new FontData("Arial", this.fontSize, SWT.BOLD)};
		Font font2 = PapyrusPlugin.fontManager.get(fontdata2);
		this.nameLabel = new Label();
		this.nameLabel.setFont(font2);
		this.nameLabel.setOpaque(false);
		this.add(this.nameLabel);
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.draw2d.Figure#getBackgroundColor()
	 */
	/**
	 * Gets the background color.
	 * 
	 * @return the background color
	 */
	@Override
	public Color getBackgroundColor() {
		return this.backgroundColor;
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.draw2d.Figure#setBackgroundColor(org.eclipse.swt.graphics.Color)
	 */
	/**
	 * Sets the background color.
	 * 
	 * @param backgroundColor the background color
	 */
	@Override
	public void setBackgroundColor(Color backgroundColor) {
		this.backgroundColor = backgroundColor;
		super.setBackgroundColor(backgroundColor);
	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#getBorderColor()
	 */
	/**
	 * Gets the border color.
	 * 
	 * @return the border color
	 */
	public Color getBorderColor() {
		return this.borderColor;
	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#setBorderColor(org.eclipse.swt.graphics.Color)
	 */
	/**
	 * Sets the border color.
	 * 
	 * @param borderColor the border color
	 */
	public void setBorderColor(Color borderColor) {
		this.borderColor = borderColor;
		super.setBorder(new LineBorder(borderColor));
	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#setIcon(org.eclipse.swt.graphics.Image)
	 */
	/**
	 * Sets the icon.
	 * 
	 * @param img the img
	 */
	public void setIcon(Image img) {
		this.img = img;
	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#getfigureFont()
	 */
	/**
	 * Getfigure font.
	 * 
	 * @return the figure font
	 */
	public String getfigureFont() {
		return this.fontString;
	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#setfigureFont(java.lang.String)
	 */
	/**
	 * Setfigure font.
	 * 
	 * @param font the font
	 */
	public void setfigureFont(String font) {



		this.fontString=font;	
		FontData[] fontdata={new FontData(font, this.fontSize, SWT.NORMAL)};
		this.font = PapyrusPlugin.fontManager.get(fontdata);
		super.setFont(this.font);
	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#getFontSize()
	 */
	/**
	 * Gets the font size.
	 * 
	 * @return the font size
	 */
	public int getFontSize() {
		return this.fontSize;
	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#setFontSize(int)
	 */
	/**
	 * Sets the font size.
	 * 
	 * @param fontSize the font size
	 */
	public void setFontSize(int fontSize) {

		FontData[] fontdata={new FontData(this.fontString, fontSize, SWT.NORMAL)};
		this.font = PapyrusPlugin.fontManager.get(fontdata);
		super.setFont(this.font);
		this.fontSize = fontSize;
	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#setFontSize(int)
	 */
	/**
	 * Sets the font.
	 * 
	 * @param f the f
	 */
	@Override
	public void setFont(Font f) {
		fontSize =f.getFontData()[0].getHeight();
		fontString =f.getFontData()[0].getName();
		int fontStyle =f.getFontData()[0].getStyle();
		this.nameLabel.setFont(PapyrusPlugin.fontManager.get(new FontData[]{
				new FontData(fontString,fontSize,fontStyle)}));
		
		
		if (this.getStereotypesLabel()!=null){
			if (fontSize>3){
				this.getStereotypesLabel().setFont(
						PapyrusPlugin.fontManager.get(new FontData[]{
								new FontData(fontString,
										fontSize-2,
										SWT.NORMAL)}));
			}
			else{
				this.getStereotypesLabel().setFont(PapyrusPlugin.fontManager.get(new FontData[]{
					new FontData(fontString,2,SWT.NORMAL)}));
			}

		}
		if(this.getQualifiedNameLabel()!=null){
			this.getQualifiedNameLabel().setFont(PapyrusPlugin.fontManager.get(new FontData[]{
					new FontData(fontString,fontSize,SWT.ITALIC)}));
		}
		
	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#getForeGroundColor()
	 */
	/**
	 * Gets the fore ground color.
	 * 
	 * @return the fore ground color
	 */
	public Color getForeGroundColor() {
		return this.foreGroundColor;
	}


	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#setForeGroundColor(org.eclipse.swt.graphics.Color)
	 */
	/**
	 * Sets the fore ground color.
	 * 
	 * @param foreGroundColor the fore ground color
	 */
	public void setForeGroundColor(Color foreGroundColor) {
		this.foreGroundColor = foreGroundColor;
		super.setForegroundColor(foreGroundColor);


	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#getLineStle()
	 */
	/**
	 * Gets the line stle.
	 * 
	 * @return the line stle
	 */
	public String getLineStle() {
		return this.lineStle;
	}


	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#setLineStle(java.lang.String)
	 */
	/**
	 * Sets the line stle.
	 * 
	 * @param lineStle the line stle
	 */
	public void setLineStle(String lineStle) {

		this.lineStle = lineStle;
	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#getLineThickness()
	 */
	/**
	 * Gets the line thickness.
	 * 
	 * @return the line thickness
	 */
	public int getLineThickness() {
		return this.LineThickness;
	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#setLineThickness(int)
	 */
	/**
	 * Sets the line thickness.
	 * 
	 * @param lineThickness the line thickness
	 */
	public void setLineThickness(int lineThickness) {
		this.LineThickness = lineThickness;
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Graphics)
	 */
	/**
	 * Paint figure.
	 * 
	 * @param graphics the graphics
	 */
	@Override
	public void paintFigure(Graphics graphics) {
		super.paintFigure(graphics);

		if (this.img != null) {
			if (this.iconLabel == null) {
				this.createIconLabel();
			}
		} else {
			if (this.iconLabel != null) {
				this.remove(this.iconLabel);	
			}
		}
	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#getFontColor()
	 */
	/**
	 * Gets the font color.
	 * 
	 * @return the font color
	 */
	public Color getFontColor() {
		return this.fontColor;
	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#setFontColor(org.eclipse.swt.graphics.Color)
	 */
	/**
	 * Sets the font color.
	 * 
	 * @param fontColor the font color
	 */
	public void setFontColor(Color fontColor) {
		this.fontColor = fontColor;
	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#refreshColors(com.cea.papyrus.diagraminterchange2.di2.GraphElement)
	 */
	/**
	 * Refresh colors.
	 * 
	 * @param graphElement the graph element
	 */
	public void refreshColors(GraphElement graphElement) {

		//set colors
		//backgroundColor

		this.setBackgroundColor(PapyrusPlugin.colorManager.get(graphElement.getBackgroundColor()));
		this.setFontColor(PapyrusPlugin.colorManager.get( graphElement.getFontColor()));
		this.setBorderColor(PapyrusPlugin.colorManager.get(graphElement.getBorderColor()));
		this.setForeGroundColor(PapyrusPlugin.colorManager.get(graphElement.getFontColor()));
		this.setFont(PapyrusPlugin.fontManager.get(new FontData[]{new FontData(graphElement.getFontFamily(),graphElement.getFontSize(),SWT.BOLD)}));
	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#refreshPresentation(java.lang.String, org.eclipse.uml2.uml.Element)
	 */
	/**
	 * Refresh presentation.
	 * 
	 * @param presentation the presentation
	 * @param selection the selection
	 */
	public void refreshPresentation(String presentation, Element selection, GraphElement ge) {

		//org.eclipse.swt.graphics.Image iconp  = (new com.cea.utils.Element(selection)).getIcon();
		org.eclipse.swt.graphics.Image icon =PapyrusPlugin.getIconElement(selection, ge);
		

		
		/* if the presentation is icon or icon with text, we can set the icon */
		if ((icon != null) 
				&& ( (presentation.equals(ModelerHelper.ICON_STEREOTYPE_PRESENTATION))
						|| presentation.equals(ModelerHelper.TEXT_ICON_STEREOTYPE_PRESENTATION)))
		{
			this.setIcon(icon);
			if(iconLabel==null){
				createIconLabel();
			}
			
			iconLabel.setIcon(icon);
			iconLabel.repaint();
			this.add(iconLabel,0);
			this.repaint();
			
		}
		else{
			if(iconLabel!=null){
				iconLabel.setIcon(null);
				iconLabel.repaint();
				if(iconLabel.getParent()!=null)
				{this.remove(iconLabel);}
				this.repaint();
			}
		}
		return;
	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#refreshStereotypes(java.lang.String, java.lang.String, boolean, boolean)
	 */
	/**
	 * Refresh stereotypes.
	 * 
	 * @param presentation the presentation
	 * @param hasIcon the has icon
	 * @param hasShape the has shape
	 * @param stereotypes the stereotypes
	 */
	public void refreshStereotypes(String stereotypes, String presentation, boolean hasIcon, boolean hasShape) {
		
		if (stereotypes.equals("")) {
			this.setStereotypes(null);
			return;
		}

		if (presentation.equals(ModelerHelper.ICON_STEREOTYPE_PRESENTATION) && hasIcon) {
			this.setStereotypes(null);
			return;
		} else if (presentation.equals(ModelerHelper.IMAGE_STEREOTYPE_PRESENTATION) && hasShape) {
			this.setStereotypes(null);
			return;
		}

		this.setStereotypes(stereotypes);//add stereotypes on the class figure		
		return;
	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#setName(java.lang.String)
	 */
	/**
	 * Sets the name.
	 * 
	 * @param name the name
	 */
	public void setName( String name )
	{
		this.nameLabel.setText(name);
	}

	/**
	 * This method is used to create the name label in the figure.
	 */
	protected void createNameLabel()
	{
		FontData[] fontdata={new FontData(this.fontString, this.fontSize, SWT.BOLD)};
		Font font = PapyrusPlugin.fontManager.get(fontdata);
		Label label = new Label();
		label.setFont(font);
		label.setForegroundColor(this.fontColor);
		label.setOpaque(false);
		// Add the name label to the figure after the stereotype label
		this.add( label, getNameLabelPosition());
		this.nameLabel = label;
	}

	/**
	 * 
	 * 
	 * @return 
	 */
	protected int getNameLabelPosition()
	{
		int position = getQualifiedNameLabelPosition();
		if( this.qualifiedLabel != null) {
			position++;
		}
		return position;
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#getNameLabel()
	 */	
	/**
	 * Gets the name label.
	 * 
	 * @return the name label
	 */
	public Label getNameLabel() {
		return this.nameLabel;
	}

	/**
	 * this method is used to create the stereotype label.
	 */
	protected void createStereotypeLabel()
	{
		FontData[] fontdata={new FontData(this.fontString, fontSize, SWT.NORMAL)};
		Font font = PapyrusPlugin.fontManager.get(fontdata);
		Label label = new Label();
		label.setFont(font);
		label.setOpaque(false);
		// Add the stereotype label to the figure at pos 0
		this.add(label, getStereotypeLabelPosition());
		this.stereotypesLabel = label;
	}
	
	/**
	 * 
	 * 
	 * @return the position of the stereotype label in the figure
	 */
	protected int getStereotypeLabelPosition()
	{
		int position = getIconLabelPosition();
		if (this.iconLabel != null) {
			 position++;
		}
		return position;
	}
	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#getStereotypesLabel()
	 */
	/**
	 * Gets the stereotypes label.
	 * 
	 * @return the stereotypes label
	 */
	public Label getStereotypesLabel() {
		return this.stereotypesLabel;
	}

	/**
	 * return the label thath contains the icon.
	 * 
	 * @return the label thaht cotnains the icon
	 */
	public Label getIconLabel() {
		return this.iconLabel;
	}

	/**
	 * used to create a label that contains the icon.
	 */
	protected void createIconLabel()
	{
		Label label = new Label();

		// Add the label to the figure, at pos 0
		this.add(label, getIconLabelPosition());
		this.iconLabel = label;
		this.iconLabel.setLabelAlignment(PositionConstants.RIGHT);
		if (this.img != null) {
			this.iconLabel.setIcon(this.img);	
		}
	}
	
	/**
	 * 
	 * 
	 * @return 
	 */
	protected int getIconLabelPosition() {
		return 0;
	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#setQualifiedName(java.lang.String)
	 */
	/**
	 * Sets the qualified name.
	 * 
	 * @param qualifiedName the qualified name
	 */
	public void setQualifiedName( String qualifiedName ) {
		if( qualifiedName == null )
		{ // Remove label if any
			if( this.qualifiedLabel != null)
			{
				this.remove(this.qualifiedLabel);
				this.qualifiedLabel = null;
			}
			return;
		}

		// Set the stereotype label
		if( this.qualifiedLabel == null )
		{
			this.createQualifiedNameLabel();
		}
		this.qualifiedLabel.setText("("+qualifiedName+")");	
	}

	/**
	 * create the label that contains the qualified name.
	 */
	protected void createQualifiedNameLabel() {
		FontData[] fontdata={new FontData(this.fontString, this.fontSize, SWT.ITALIC)};
		Font font = PapyrusPlugin.fontManager.get(fontdata);
		Label label = new Label();
		label.setFont(font);
		label.setOpaque(false);
		// Add the label to the figure, after the name
		this.add( label, getQualifiedNameLabelPosition());
		this.qualifiedLabel = label;
	}

	/**
	 * 
	 * 
	 * @return 
	 */
	protected int getQualifiedNameLabelPosition()
	{
		int position = getStereotypeLabelPosition();
		if( this.stereotypesLabel != null) {
			position++;
		}
		return position;
	}
	
	/**
	 * return the label that contains the qualified name.
	 * 
	 * @return the  label that contains the qualified name
	 */
	public Label getQualifiedNameLabel() {
		return this.qualifiedLabel;
	}

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#getLabelAt(org.eclipse.draw2d.geometry.Point)
	 */
	/**
	 * Gets the label at.
	 * 
	 * @param pt the pt
	 * 
	 * @return the label at
	 */
	public Label getLabelAt(Point pt) {
		if( this.labelContainsPoint(this.stereotypesLabel, pt) ) {
			return this.stereotypesLabel;
		}
		if( this.labelContainsPoint(this.nameLabel, pt) ) {
			return this.nameLabel;
		}
		// Nothing found
		return null;
	}

	/**
	 * return true inf the label in localized at the point pt.
	 * 
	 * @param label the label that we look for
	 * @param pt the point thaht we test
	 * 
	 * @return true if the point is on the label
	 */
	protected boolean labelContainsPoint(Label label, Point pt) {
		Rectangle rc;

		rc = new PrecisionRectangle(label.getBounds());
		label.translateToAbsolute(rc);
		if (rc.contains(pt)) {
			return true;
		}
		return false;
	}
	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#refreshQualifiedName(com.cea.papyrus.diagraminterchange2.di2.GraphElement, com.cea.papyrus.diagraminterchange2.di2.GraphElement)
	 */
	/**
	 * Refresh qualified name.
	 * 
	 * @param element the element
	 * @param currentge the currentge
	 * @param parentge the parentge
	 */
	public void refreshQualifiedName(GraphElement parentge, GraphElement currentge, NamedElement element){
		//lok for the real uml parent of the element
		Element graphicalumlParent=null;
		if (parentge!=null){
			//in the case of diagram
			if (parentge instanceof Diagram) {
				if (((Diagram)parentge).getOwner()!=null) {
					graphicalumlParent=((Uml1SemanticModelBridge)((Diagram)parentge).getOwner()).getElement();
				}
			}
			else{
				if (parentge.getSemanticModel()!=null) {
					graphicalumlParent=((Uml1SemanticModelBridge)parentge.getSemanticModel()).getElement();
				}
			}
		}
//		compare uml prants
		if (graphicalumlParent!=null) {

			if (!(graphicalumlParent.equals(element.getOwner()))) {
				this.setQualifiedName(element.getQualifiedName());
			}
		}
	}


	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#setStereotypes(java.lang.String)
	 */
	/**
	 * Sets the stereotypes.
	 * 
	 * @param stereotypes the stereotypes
	 */
	public void setStereotypes(String stereotypes) {		
		if( stereotypes == null ) { 
			// Remove label if any
			if( this.stereotypesLabel != null) {
				this.remove(this.stereotypesLabel);
				this.stereotypesLabel = null;
			}
			return;
		}

		// Set the stereotype label
		if( this.stereotypesLabel == null ) {
			this.createStereotypeLabel();
		}

		// Set stereotype text on figure
		if (!stereotypes.equals("")) {
			this.stereotypesLabel.setText(PapyrusPlugin.ST_LEFT+stereotypes+PapyrusPlugin.ST_RIGHT);	
		} else {
			this.stereotypesLabel.setText("");
		}
	}
	
	
	/**
	 * Copy context to.
	 * 
	 * @param fig the fig
	 */
	public void copyContextTo(IFigure fig){
		Iterator it =this.getListeners(FigureListener.class);
		while(it.hasNext()){	
			fig.addFigureListener((FigureListener)it.next());
		}

		
	}
	
	/**
	 * Stereotypes label.
	 * 
	 * @param editPart the edit part
	 * @param graphNode 	 *
	 * 
	 * @return the String containing the stereotypes to display
	 */
	public String stereotypesLabel(GraphNodeWithSemanticEditPart editPart) {
		if(editPart.getGraphNode().getSemanticModel().getPresentation().equals(ModelerHelper.STEREOTYPE_TEXT_VERTICAL_PRESENTATION)) {
			return editPart.verticalStereotypesToDisplay();
		} else {
			return editPart.horizontalStereotypesToDisplay();
		}
	}
	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.figures.IAbstractElementFigure#getMinimumWidth()
	 */
	public Dimension getMinimumDimension() {
		int width=getNameLabel().getTextBounds().width+10;
		int height= getNameLabel().getTextBounds().height+10;
		int temporysize=0;
		if( getStereotypesLabel()!=null){
			temporysize=getStereotypesLabel().getTextBounds().width+10;
			height=height+getStereotypesLabel().getTextBounds().height;
			if(width<temporysize){
				width=temporysize;
			}
		}
		if(getQualifiedNameLabel()!=null){
			temporysize=getQualifiedNameLabel().getTextBounds().width+10;
			height=height+getQualifiedNameLabel().getTextBounds().height;
			if(width<temporysize){
				width=temporysize;
			}
		}
		return new Dimension(width,height);
	}
}
